/**
 * Created by bournewang on 2017/11/24.
 */
moduleStudyMap.controller('SetupQuestionnaireController', function ($scope, $log, LoadingService, DialogService,
                                                                    QuestionnaireResource, GaugeResource) {

    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
    });

    $scope.cancel = function () {
        DialogService.close();
    };
    $scope.queryGaugeTemplates = function () {
        //LoadingService.show();
        GaugeResource.findByKey({}, {key: $scope.gaugeTemplateKey}, function (gaugeTemplates) {
            $log.debug("勋章匹配结果", gaugeTemplates);
            $scope.gaugeTemplates = gaugeTemplates;
            //LoadingService.hide();
        });
    };

    $scope.setCurrentQuestionnaire = function (gaugeTemplate) {
        if (!$scope.currentQuestionnaire) {
            $scope.currentQuestionnaire = {};
        }
        $scope.currentQuestionnaire.gaugeTemplate = gaugeTemplate;
    };

    $scope.submit = function () {
        if ($scope.currentQuestionnaire && $scope.currentQuestionnaire.gaugeTemplate) {
            //LoadingService.show();
            QuestionnaireResource.save({groupId: $scope.currentGroup.id},
                {gaugeTemplateId: $scope.currentQuestionnaire.gaugeTemplate.gaugeTemplateId}, function () {
                    //LoadingService.hide();
                    DialogService.close();
                    Alert.success("成功了");
                    $scope.getStudyClassGroupList();
                })
        } else {
            Alert.error("你还没选问卷呢");
        }
    };


});
